// packageI/pages/storageApproval/storageApproval.js
const app = getApp()
var applet_park_api_url = app.globalData.applet_park_api_url;
var applet_park_api_url_imgUrl = app.globalData.applet_park_api_url_imgUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: applet_park_api_url_imgUrl,
    token: wx.getStorageSync('TOKEN'),
    storeList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.getInfos()
  },
  getInfos() {
    var that = this
    wx.request({
      url: applet_park_api_url + '/api/consumableBillDetail/auditorBillDetails',
      method: "GET",
      header: {
        Authorization: that.data.token
      },
      success: function (res) {
        if (res.data.code == 0) {
          for (var i in res.data.data) {
            if (res.data.data[i].images != null) {
              res.data.data[i].images = res.data.data[i].images.split(',')[0]
            }
            res.data.data[i].createdTime = res.data.data[i].createdTime.substring(0, 10)
          }
          that.data.storeList = res.data.data
          that.setData(that.data)
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
      }
    })
  },
  submit(e) {
    var that = this
    var status = e.currentTarget.dataset.type
    if (status == 1) {
      status = 4
    } else {
      status = 1
    }
    wx.request({
      url: applet_park_api_url + '/api/consumableBillDetail/audit',
      method: 'PUT',
      header: {
        Authorization: that.data.token
      },
      data: {
        id: e.currentTarget.dataset.id,
        billStatus: status
      },
      success: function (res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '操作成功',
          })
          that.getInfos()
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})